package summoning2;

import impsoft.bots.reflection.Interface;
import impsoft.scripting.ibot.builtin.itemrec.ItemSlot;
import impsoft.scripting.types.ColorSkeltonScriptable;
import impsoft.utils.uber.UberScriptUtils;

import java.awt.Rectangle;
import java.util.ArrayList;
import java.util.List;

import looting.LootItemLoader;

public class FamiliarItemSlot extends ItemSlot {

	public FamiliarItemSlot(int index, ColorSkeltonScriptable cs) {
		super(0, 0, index, cs);
	}

	@Override
	public int getStackSize() throws InterruptedException {
		Interface interfaces[] = getInterfaceChildren();
		if (interfaces != null) {
			int i = interfaces[index].getItemStackSize();
			if (i > 0) {
				return i;
			}
		}
		return -1;
	}

	public int getID() throws InterruptedException {
		Interface interfaces[] = getInterfaceChildren();
		if (interfaces != null) {
			int i = interfaces[index].getItemId();
			if (i > 0) {
				return i;
			}
		}
		return -1;
	}

	@Override
	public String getItemName() {
		return getName();
	}

	public String getName() {
		Interface interfaces[] = getInterfaceChildren();
		if (interfaces != null) {
			int i = interfaces[index].getItemId();
			if (i > 0) {
				return UberScriptUtils.getName(i);
			}
		}
		return null;
	}

	@Override
	public Rectangle getArea() {
		Interface interfaces[] = getInterfaceChildren();
		if (interfaces != null) {
			return interfaces[index].getCalculatedArea3();
		}

		return null;
	}

	public boolean isStackable() throws InterruptedException {
		return LootItemLoader.isStackable(getID());
	}

	@Override
	public boolean isItemInSlot() throws InterruptedException {
		Interface interfaces[] = getInterfaceChildren();
		if (interfaces != null) {
			return interfaces[index].getItemId() > 0;
		}
		return false;
	}

	@Override
	public boolean isSelected() {
		return false;
	}

	public Interface[] getInterfaceChildren() {
		List<Interface> itemList = new ArrayList<Interface>();
		Interface inventory = cs.getInterfaceAtIndex(671, 27);

		if (inventory != null && inventory.isValid()) {
			Interface[] items = inventory.getChildren();

			for (Interface item : items) {
				itemList.add(item);
			}
		}

		return itemList.toArray(new Interface[itemList.size()]);
	}

}